package com.cykj.service.impl;

import com.cykj.mapper.OrderMapper;
import com.cykj.pojo.CyOrder;
import com.cykj.service.OrderService;
import com.cykj.util.ResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public ResponseDto getAllOrder() {
        List<CyOrder> allOrder = orderMapper.getAllOrder();
        return new ResponseDto(1,"订单查询成功",allOrder);
    }

    @Override
    public ResponseDto alterStatus(String orderExaminationId, int status) {
        int i = orderMapper.alterStatus(orderExaminationId, status);
        if (i == 0){
            return new ResponseDto(0,"暂未修改",null);
        }else {
            return new ResponseDto(1,"修改成功",null);

        }
    }

    @Override
    public ResponseDto getProjectPrice(int status,String name) {
        double projectPrice;
        if (status == 1){
            projectPrice = orderMapper.getProjectPrice(name);
        }else {
            projectPrice = orderMapper.getProjectPrice2(name);
        }

        return new ResponseDto(1,"返回成功",projectPrice);
    }

    @Override
    public ResponseDto getDepartName(int status,String name) {
        String departName="";
        if (status == 1){
            //如果状态为1说明是项目
            departName = orderMapper.getDepartName(name);
        }else {
            //说明是套餐 ---》获取所有的项目名 ---》再去找对应的科室
            List<String> proName = orderMapper.getProName(name);
            for (int i = 0; i < proName.size(); i++) {
                String departName1 = orderMapper.getDepartName(proName.get(i));
                String temp = departName1 + "-" + proName.get(i);
                if (i != proName.size()-1){
                    //返回 科室-项目&科室-项目
                    departName = departName + temp + "&";
                }else {
                    departName = departName + temp;
                }

            }

        }
        return new ResponseDto(1,"返回成功",departName);
    }
    @Override
    public ResponseDto dealName(int id) {
        String s = orderMapper.dealName(id);
        return new ResponseDto(1,"查询成功",s);
    }

    //获取到项目名
    @Override
    public ResponseDto getProName(String name) {
        List<String> proName = orderMapper.getProName(name);
        return new ResponseDto(1,"查询成功",proName);
    }

    @Override
    public ResponseDto getInfo(String id,int sort) {
        System.out.println("------------"+sort);
        List<CyOrder> info = orderMapper.getInfo(id, sort);
        if (info != null){
            return new ResponseDto(1,"查询成功",info);
        }else {
            return new ResponseDto(0,"查询成功",null);
        }

    }
}
